package com.breeze.blockchain.controller.admin.form.setting;

import static com.breeze.blockchain.mybatis.entity.table.SettingTable.SETTING;

import com.breeze.blockchain.mybatis.entity.SettingDo;
import com.breeze.components.mybatis.page.AbstractPageQuery;
import com.mybatisflex.core.query.If;
import com.mybatisflex.core.query.QueryWrapper;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @author breeze
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Schema
public class SettingPageForm extends AbstractPageQuery<SettingDo> {

  @Schema(title = "配置key")
  String key;

  @Schema(title = "配置名称")
  String name;

  @Schema(title = "是否公开配置")
  Integer isPublic;

  @Override
  public QueryWrapper toQueryWrapper() {
    return super.toQueryWrapper()
        .where(
            SETTING
                .NAME
                .like(getName(), If::hasText)
                .and(SETTING.KEY.eq(getKey(), If::hasText))
                .and(SETTING.IS_PUBLIC.eq(getIsPublic(), If::notNull)))
        .orderBy(SETTING.ID.desc());
  }
}
